
/***************************************************************************************
****************************************************************************************
* FILE		: hotCompress.c
* Description	: 
*			  
* Copyright (c) 2020 by Simlife. All Rights Reserved.
* 
* History:
* Version		Name		Date				Description
   0.1		Alen			2020/05/07		Initial Version
   
****************************************************************************************
****************************************************************************************/

#include "includes.h"

void initHotCompressControlPin(void)
{
	heat1ControlTypeControl &= heat1ControlPinReverse;	 //output
	heat1ControlPullUpControl &= heat1ControlPinReverse; //no pull up
	HEAT1_OFF();
}

void closeHotCompressPin(void)
{
	HEAT1_OFF();
}

// void hotCompressJudge(U16 heatADC)
// {
// 	if (heatADC > HEAT_NTC_SHORT || heatADC < HEAT_NTC_OPEN)
// 	{
// 		stSystem.heatMode = OFF;
// 		HEART_OFF();
// 	}
// 	else
// 	{
// 		if (heatADC > HEAT_MAX_ADCV)
// 		{
// 			HEART_OFF();
// 		}
// 		else if (heatADC < TEMP_44)
// 		{
// 			HEART_ON();
// 		}
// 	}
// }

void hotCompressPWMProcess(void) //200us call
{
	if (stSystem.heatMode == HEAT_MODE_OFF)
	{
		return;
	}

	if (flagHeat)
	{
		if (stTime.countHeat < stTime.countHeatPWM)
		{
			HEAT1_ON();
		}
		else
		{
			HEAT1_OFF();
		}

		stTime.countHeat++;
		if (stTime.countHeat > 99)
		{
			stTime.countHeat = 0;
		}
	}
}

// #define MAXPWM_TIME_1 8 //4s
#define MAXPWM 20
#define MODE_1_TIME 16 //8s

void hotCompressSet(void)
{
	if (stSystem.heatMode == HEAT_MODE_OFF)
	{
		HEAT1_OFF();
	}
	else
	{
		stTime.countHeat = 0;
		flagHeat = TRUE;
		// if (stSystem.heatMode == HEAT_MODE_1)
		{
			stTime.countHeatMaxHigh = 0;
			stTime.countHeatPWM = MAXPWM;
			stTime.countHeatChangeTime = MODE_1_TIME;
		}
		// else
		// {
		// 	stTime.countHeatMaxHigh = MAXPWM_TIME_1;
		// 	stTime.countHeatPWM = MAXPWM;
		// 	stTime.countHeatChangeTime = 0;
		// }
	}
}

void hotCompressProcess(void) // 500ms call
{
	if (stSystem.heatMode == HEAT_MODE_OFF)
	{
		return;
	}

	// if (stSystem.heatMode == HEAT_MODE_1)
	{
		stTime.countHeatChangeTime--;
		if (stTime.countHeatChangeTime == 0)
		{
			if (flagHeat)
			{
				flagHeat = FALSE;
				stTime.countHeatChangeTime = 8; //4s
				HEAT1_OFF();
				stTime.countHeat = 0;
			}
			else
			{
				flagHeat = TRUE;
				stTime.countHeatChangeTime = MODE_1_TIME; //8s
				HEAT1_ON();
			}
		}
	}
	// else
	// {
	// 	if (stTime.countHeatMaxHigh != 0)
	// 	{
	// 		stTime.countHeatMaxHigh--;
	// 		if (stTime.countHeatMaxHigh == 0)
	// 			stTime.countHeatPWM = 15;
	// 	}
	// }
}
